#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N=5*1e4+10;

vector<pair<int,int>> edge[N];
int dist[N];
int st[N];

void spfa()
{
	memset(dist,-0x3f,sizeof(dist));
	dist[0]=0;
	
	queue<int> q;
	q.push(0);
	st[0]=1;
	while(q.size())
	{
		int r=q.front();
		st[r]=0;
		q.pop();
		for(auto& e:edge[r])
		{
			int p=e.first;
			if(dist[p]<dist[r]+e.second)
			{
				dist[p]=dist[r]+e.second;
				if(!st[p])
				{
					q.push(p);
					st[p]=1;
				}
			}
		}
	}
}
int main()
{
	
	int n;
	cin>>n;
	for(int i=1;i<N;i++)
	{
		edge[i-1].push_back({i,0});
		edge[i].push_back({i-1,-1});
	}
	for(int i=1;i<=n;i++)
	{
		
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a++,b++;
		edge[a-1].push_back({b,c});
	}
	spfa();
	
	cout<<dist[50001];
	return 0;
}
